﻿// Decompiled with JetBrains decompiler
// Type: MCM.LightInject.ScopeManager
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System.Diagnostics.CodeAnalysis;

#nullable disable
namespace MCM.LightInject
{
  [ExcludeFromCodeCoverage]
  internal abstract class ScopeManager : IScopeManager
  {
    protected ScopeManager(IServiceFactory serviceFactory) => this.ServiceFactory = serviceFactory;

    public abstract Scope CurrentScope { get; set; }

    public IServiceFactory ServiceFactory { get; }

    public Scope BeginScope()
    {
      Scope scope = new Scope((IScopeManager) this, this.CurrentScope);
      this.CurrentScope = scope;
      return scope;
    }

    public void EndScope(Scope scope)
    {
      Scope parentScope = scope.ParentScope;
      if (this.CurrentScope != scope)
        return;
      this.CurrentScope = parentScope;
    }

    protected Scope GetThisScopeOrFirstValidAncestor(Scope scope)
    {
      while (scope != null && scope.IsDisposed)
        scope = scope.ParentScope;
      this.CurrentScope = scope;
      return scope;
    }
  }
}
